package main

import (
	"fmt"
	"github.com/spf13/cobra"
	"log"
	"os"
	"tanbao2/config"
	"tanbao2/http"
	"tanbao2/mysql"
)

var rootCmd = &cobra.Command{
	Use:   "im",
	Short: "tanbao grpc im service",
	Run:   runServer,
}

var (
	configFile = "./config.yml"
)

func main() {
	f := rootCmd.Flags()
	f.StringVarP(&configFile, "serviceConfig", "a", configFile, "service config file")

	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func runServer(cmd *cobra.Command, args []string) {
	fmt.Printf("current configFile:%s\n\n", configFile)
	if configFile == "" {
		log.Fatalf("missing the service config file that should be a yml file.")
		return
	}
	config.LoadServerConfig(configFile)
	mysql.InitDB()
	http.InitRegisterMethods()
	http.InitNet()
}
